package com.yserp.project.erp.common.util;/**
 * Created with IDEA
 * author:Carl
 * Date:2022/8/15
 * Time:10:34
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yserp.framework.web.domain.BaseEntity;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Map;

/**
 * @author carl
 * @date 2022年08月15日 10:34
 */
public class DateSearchUtils {

    /**
     * 查询时间区间
     * @param t
     * @param queryWrapper
     */
    public static void queryDateRange(BaseEntity t,QueryWrapper<?> queryWrapper){
        queryDateRangeByFiled(t,queryWrapper,"order_date");
    }

    /**
     * 查询时间区间
     * @param t
     * @param queryWrapper
     * @param filed  基于该字段查询
     */
    public static void queryDateRangeByFiled(BaseEntity t,QueryWrapper<?> queryWrapper,String filed){
        //对时间区间的处理
        Map<String, Object> params = t.getParams();
        if(null != params){
            Object beginTime = params.get("beginTime");
            Object endTime = params.get("endTime");
            if(ObjectUtils.isNotEmpty(beginTime)){
                queryWrapper.ge(filed,beginTime);
            }
            if(ObjectUtils.isNotEmpty(endTime)){
                queryWrapper.le(filed,endTime);
            }
        }
    }

}
